<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  
</head>
<body>
  <div id="app">
    <common-head></common-head>
  </div>
  <script src="./vue.js"></script>
  <script>
    // 全局组件
    const CommonHead =  {
      template: `
        <div> 
          <h1>我是一个公共头部组件</h1>
          <button class="btn" @click="changeMsg">增加li</button>
          <ul class="oul">
            <li v-for="item in arr" :key="item"> {{item}} </li>  
          </ul>
        </div>
      `,
      data(){
        return {
          arr: [1,2,3]
        }
      },
      methods:{
        changeMsg(){
          this.arr.push(this.arr.length+1);
          this.$nextTick(()=>{
            const oul = document.querySelector('.oul');
            console.log(oul.children)
          })
        }
      },
      beforeCreate() {
        console.log('实例初始化完成之前')
      },
      created(){
        console.log('初始化已经完成')
        
      },
      beforeMount() {
        console.log('模板渲染之前');
        console.log(document.querySelector('.btn'))
        
      },
      mounted() {
        console.log('模板渲染已经完成')
        console.log(document.querySelector('.btn'))
      },
      beforeUpdate() {
        console.log('数据改变视图更新之前');
        /* const oul = document.querySelector('.oul');
        console.log(oul.children) */
      },
      updated(){
        console.log('数据改变视图已经更新');
        /* const oul = document.querySelector('.oul');
        console.log(oul.children) */
      },
      beforeDestroy() {
        console.log('实例销毁之前')
      },
      destroyed() {
        console.log('实例已经销毁')
      },
    }
    Vue.component('CommonHead', CommonHead)
    const vm = new Vue({
      el: '#app',
      data:{
      
      }
      
    })
  </script>
</body>
</html>